// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueResource from 'vue-resource'
import store from './store/store'
import util from './util/util'
import FastClick from 'fastclick'
import $ from 'jquery'
window.$ = $

Vue.use(VueResource)
Vue.use(util)

//将提交的对象转成对应的参数
Vue.http.options.emulateJSON = true
//http提交前loading
Vue.http.interceptors.push(function (request, next) {
  let hasLoadEnd = false      // 是否已加载结束
  // 如果加载速度在500毫秒内，则不出现加载框
  setTimeout(function(){
    if (!hasLoadEnd) {
      store.commit('showLoading', '加载中')
    }
  },500);

  next(function (response) {
    if(response.body.code == '50018'){
      store.commit('showToast', '请先登录')
      router.replace({name: 'Login'})
    }

    hasLoadEnd = true
    store.commit('hideLoading')
  })
})

FastClick.attach(document.body)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
